package com.sptpc.demo1.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;
import org.joda.money.Money;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;


/**
 * 接收前端参数 （modifyDrink）参数
 */
@Data //@Setter  @Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "t_drink")
public class Drink {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer id;  //编号

    /**
     * @Column =(name ="name")
     * 对象与数据库name完全一样就可以省略
     * <p>
     * 自动对应 JAVA 与 MYSQL
     * JAVA 驼峰命名 adminssionDate Mysql数据库 下划线 adminssion_date
     */
    @Column
    @NotBlank(message = "名字不能为空")
    public String name; //名字


    @NotNull
    @Column
    @Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount",
            parameters = {@org.hibernate.annotations.Parameter(name = "currencyCode", value = "CNY")})
    public Money price; //饮品价格
    //  public LocaleData enrollData; //上架时间

    @ManyToOne
    @JsonIgnoreProperties(value = {"hibernateLazyInitializer"})
    public Category category;
}
